<template>
  <el-dialog
     v-drag
    :title="!dataForm.payId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它" prop="payPype">
  <el-input size="mini"  v-model="dataForm.payPype" placeholder="支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它" clearable></el-input>
</el-form-item>
<el-form-item label="1:销售, -1:退货" prop="saleType">
  <el-input size="mini"  v-model="dataForm.saleType" placeholder="1:销售, -1:退货" clearable></el-input>
</el-form-item>
<el-form-item label="销售id" prop="saleId">
  <el-input size="mini"  v-model="dataForm.saleId" placeholder="销售id" clearable></el-input>
</el-form-item>
<el-form-item label="销售编号" prop="saleNo">
  <el-input size="mini"  v-model="dataForm.saleNo" placeholder="销售编号" clearable></el-input>
</el-form-item>
<el-form-item label="支付编号" prop="payNo">
  <el-input size="mini"  v-model="dataForm.payNo" placeholder="支付编号" clearable></el-input>
</el-form-item>
<el-form-item label="支付日期" prop="payDate">
  <el-input size="mini"  v-model="dataForm.payDate" placeholder="支付日期" clearable></el-input>
</el-form-item>
<el-form-item label="总支付金额" prop="payFee">
  <el-input size="mini"  v-model="dataForm.payFee" placeholder="总支付金额" clearable></el-input>
</el-form-item>
<el-form-item label="其它支付金额" prop="otherFee">
  <el-input size="mini"  v-model="dataForm.otherFee" placeholder="其它支付金额" clearable></el-input>
</el-form-item>
<el-form-item label="社保卡支付金额" prop="socialFee">
  <el-input size="mini"  v-model="dataForm.socialFee" placeholder="社保卡支付金额" clearable></el-input>
</el-form-item>
<el-form-item label="支付码" prop="authCode">
  <el-input size="mini"  v-model="dataForm.authCode" placeholder="支付码" clearable></el-input>
</el-form-item>
<el-form-item label="支付交易码" prop="tradeNo">
  <el-input size="mini"  v-model="dataForm.tradeNo" placeholder="支付交易码" clearable></el-input>
</el-form-item>
<el-form-item label="接收金额" prop="receiveFee">
  <el-input size="mini"  v-model="dataForm.receiveFee" placeholder="接收金额" clearable></el-input>
</el-form-item>
<el-form-item label="实际金额" prop="realFee">
  <el-input size="mini"  v-model="dataForm.realFee" placeholder="实际金额" clearable></el-input>
</el-form-item>
<el-form-item label="找零金额" prop="changeFee">
  <el-input size="mini"  v-model="dataForm.changeFee" placeholder="找零金额" clearable></el-input>
</el-form-item>
<el-form-item label="营业员" prop="sellUser">
  <el-input size="mini"  v-model="dataForm.sellUser" placeholder="营业员" clearable></el-input>
</el-form-item>
<el-form-item label="营业员id" prop="sellUserId">
  <el-input size="mini"  v-model="dataForm.sellUserId" placeholder="营业员id" clearable></el-input>
</el-form-item>
<el-form-item label="0:线下支付， 1：线上支付" prop="isOnlinePay">
  <el-input size="mini"  v-model="dataForm.isOnlinePay" placeholder="0:线下支付， 1：线上支付" clearable></el-input>
</el-form-item>
<el-form-item label="优惠券信息" prop="couponInfo">
  <el-input size="mini"  v-model="dataForm.couponInfo" placeholder="优惠券信息" clearable></el-input>
</el-form-item>
<el-form-item label="门店id" prop="storeId">
  <el-input size="mini"  v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
</el-form-item>
<el-form-item label="门店名称" prop="storeName">
  <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
</el-form-item>
<el-form-item label="门店编码" prop="storeCode">
  <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
  <el-input size="mini"  v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
</el-form-item>
<el-form-item label="修改时间" prop="updateTime">
  <el-input size="mini"  v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
</el-form-item>
<el-form-item label="创建人" prop="createUsername">
  <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
</el-form-item>
<el-form-item label="创建人id" prop="createUserId">
  <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
</el-form-item>
<el-form-item label="修改人" prop="updateUsername">
  <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
</el-form-item>
<el-form-item label="修改人id" prop="updateUserId">
  <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
</el-form-item>
<el-form-item label="是否可用 1:是" prop="status">
  <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="版本" prop="version">
  <el-input size="mini"  v-model="dataForm.version" placeholder="版本" clearable></el-input>
</el-form-item>
<el-form-item label="是否删除 1:是" prop="isDeleted">
  <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark">
  <el-input size="mini"  v-model="dataForm.remark" placeholder="备注" clearable></el-input>
</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          payId: 0,
          payPype: '',
          saleType: '',
          saleId: '',
          saleNo: '',
          payNo: '',
          payDate: '',
          payFee: '',
          otherFee: '',
          socialFee: '',
          authCode: '',
          tradeNo: '',
          receiveFee: '',
          realFee: '',
          changeFee: '',
          sellUser: '',
          sellUserId: '',
          isOnlinePay: '',
          couponInfo: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          version: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          payPype: [
            { required: true, message: '支付类型 1:现金，2:支付宝,3:微信,4:社保卡,5:银联,6:其它不能为空', trigger: 'blur' }
          ],
          saleType: [
            { required: true, message: '1:销售, -1:退货不能为空', trigger: 'blur' }
          ],
          saleId: [
            { required: true, message: '销售id不能为空', trigger: 'blur' }
          ],
          saleNo: [
            { required: true, message: '销售编号不能为空', trigger: 'blur' }
          ],
          payNo: [
            { required: true, message: '支付编号不能为空', trigger: 'blur' }
          ],
          payDate: [
            { required: true, message: '支付日期不能为空', trigger: 'blur' }
          ],
          payFee: [
            { required: true, message: '总支付金额不能为空', trigger: 'blur' }
          ],
          otherFee: [
            { required: true, message: '其它支付金额不能为空', trigger: 'blur' }
          ],
          socialFee: [
            { required: true, message: '社保卡支付金额不能为空', trigger: 'blur' }
          ],
          authCode: [
            { required: true, message: '支付码不能为空', trigger: 'blur' }
          ],
          tradeNo: [
            { required: true, message: '支付交易码不能为空', trigger: 'blur' }
          ],
          receiveFee: [
            { required: true, message: '接收金额不能为空', trigger: 'blur' }
          ],
          realFee: [
            { required: true, message: '实际金额不能为空', trigger: 'blur' }
          ],
          changeFee: [
            { required: true, message: '找零金额不能为空', trigger: 'blur' }
          ],
          sellUser: [
            { required: true, message: '营业员不能为空', trigger: 'blur' }
          ],
          sellUserId: [
            { required: true, message: '营业员id不能为空', trigger: 'blur' }
          ],
          isOnlinePay: [
            { required: true, message: '0:线下支付， 1：线上支付不能为空', trigger: 'blur' }
          ],
          couponInfo: [
            { required: true, message: '优惠券信息不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '门店id不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.payId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.payId) {
            const res = await this.$http({
              url: `/sale/salepayorder/info/${this.dataForm.payId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.salePayOrder
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/sale/salepayorder/${!this.dataForm.payId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
